<?php
/*
 * @Author: your name
 * @Date: 2020-05-21 16:50:32
 * @LastEditTime: 2020-05-22 16:58:30
 * @LastEditors: Please set LastEditors
 * @Description: In User Settings Edit
 * @FilePath: /v3/application/adminapiv3/controller/attackLogManage/fileLogManage/AutoDefenseController.php
 */ 
namespace app\adminapiv3\controller\attackLogManage\fileLogManage;

use app\adminapiv3\controller\Base;
use app\adminapiv3\service\attackLogManage\AttackLogService;
use app\adminapiv3\service\attackLogManage\fileLogManage\AutoDefenseService;
use app\adminapiv3\service\attackLogManage\fileLogManage\FileLogService;

class AutoDefenseController extends Base
{
    /**
     * @name: 列表
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-21 16:52:00
     */
    function list ()
    {
        $input['attack_dest'] = $this->filterInput('attack_dest', 'get');//主机名
        $input['path'] = $this->filterInput('path', 'get');//文件路径
        $input['atime'] = $this->filterInput('atime', 'get');//攻击时间
        $input['level'] = $this->filterInput('level', 'get');//风险级别
        $input['handle'] = $this->filterInput('handle', 'get');//处理结果 已隔离1 已恢复2

        $input['limit'] = $this->filterInput('limit', 'get', 10);//

        $AutoDefenseService = new AutoDefenseService();
        $data = $AutoDefenseService->list($input);
        
        $this->jsonOutPut($data);
    }

        /**
     * @name: 批量删除
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 10:54:26
     */
    function bulkDelete ()
    {
        global $logContent;
        $logContent = '批量删除主动防御日志';

        $id_s = $this->filterInput('id*', 'post');//删除id


        $FileLogService = new FileLogService();
        $FileLogService->delete($id_s);

        $this->jsonOutPut();
    }

    /**
     * @name: 清空所有
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 10:54:45
     */
    function clear ()
    {
        global $logContent;
        $logContent = '清空主动防御日志';

        $FileLogService = new FileLogService();
        $FileLogService->clear();

        $this->jsonOutPut();
    }

    /**
     * @name: 文件恢复
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 13:25:06
     */
    function fileReset ()
    {
        global $logContent;
        $logContent = '主动防御文件恢复';

        $id = $this->filterInput('id*', 'post');
        $host_id = $this->filterInput('host_id*', 'post');

        $baseServer = new \app\adminapiv3\service\Base();
        $baseServer->checkOptionHost($host_id);

        $FileLogService = new FileLogService();
        $FileLogService->fileRest($id, $host_id);

        $this->jsonOutPut([], true);

        $this->Async('Defense', 'Recoverys', ['id' => $id]);
    }

    /**
     * @name: 数据包
     * @Param: 
     * @Description: 
     * @Author: foo
     * @Date: 2020-05-22 09:59:47
     */
    function dataPackage ()
    {
        $host_id = $this->filterInput('host_id*', 'post');//主机id
        $event_id = $this->filterInput('event_id*', 'post');//类型
        $atime = $this->filterInput('atime*', 'post');//攻击时间
        $FileLogService = new FileLogService();
        $data = $FileLogService->dataPackage($host_id, $event_id, $atime);

        jsonErrorOut('success', 200, $data);
    }
}